zip32.dll
Otázka od: likeapear
23. 9. 2002 7:15
Pouzivate nekdo InfoZip knihovnu zip32.dll (a jeho delphi-interface)? Ja
jsem narazil na takovy preblem:
Pred spakovanim souboru nastavuji v recordu TZPOpt promennou szRootDir (tj.
korenovy adresar), ktera je typu PChar. Pokud to nastavim jako konstantni
retezec, funguje to spravne. Pokud vsak pretypuju Stringovou promennou na
PChar nefunguje to. Dokonce jsem zkousel PChar naplnit pomoci StrAlloc a
StrPCopy a predat ho, ale to taky nepomohlo. Vite nekdo o nejakem reseni?
Myslite si, ze je to chyba v te dll? Nerad bych se ji vzdaval - mame ji v
instalaci a rok ji bez problemu pouzivame (zatim jsme vsak nepotrebovali
szRootDir....)
likeapear
Odpovedá: Pavel Gazda
23. 9. 2002 10:59
> korenovy adresar), ktera je typu PChar. Pokud to nastavim jako konstantni
> retezec, funguje to spravne. Pokud vsak pretypuju Stringovou promennou na
> PChar nefunguje to. Dokonce jsem zkousel PChar naplnit pomoci StrAlloc a
> StrPCopy a predat ho, ale to taky nepomohlo. Vite nekdo o nejakem reseni?
Zkus napsat cely postup (vcetne deklarace) , asi tam mas chybu.
Pavel
Odpovedá: likeapear
23. 9. 2002 9:15
> Zkus napsat cely postup (vcetne deklarace) , asi tam mas chybu.
> Pavel
posilam cely unit, snad to admin prezije...
D_Zip32 a D_UnZip32 jsou orig. unity s rozhranim k dll. problem nastava ve
funkci ZipFiles...
unit D_Web_Procs;
interface
uses
Windows, SysUtils, Classes, D_Zip32, D_UnZip32;
function ZipFiles(ZipName : string; FileList: TStrings; JunkDir: boolean;
RootDir: String): boolean;
function ZipFile(ZipName, FileName : string; JunkDir: boolean; RootDir:
String): boolean;
function UnZipFiles(FileName,Dir: String): boolean;
implementation
function ZipProcPrint(Buffer: PChar; Size: ULONG): integer; stdcall;
begin
Result:=Size;
end;
function ZipProcPassword(P: PChar; N: Integer; M, Name: PChar): integer;
stdcall;
begin
Result:=1;
end;
function ZipProcComment(Buffer: PChar): PChar; stdcall;
begin
Result:=Buffer;
end;
function ZipProcService(Buffer: PChar; Size: ULONG): integer; stdcall;
begin
Result:=0;
end;
procedure ZipSetProcInitFunctions(var Z:TZipUserFunctions);
begin
with Z do
begin
@Print := @ZipProcPrint;
@Comment := @ZipProcComment;
@Password := @ZipProcPassword;
@Service := @ZipProcService;
end;
ZpInit(Z);
end;
function ZipFiles(ZipName : string; FileList: TStrings; JunkDir: boolean;
RootDir: String): boolean;
var
i : integer;
ZipRec : TZCL;
ZUF : TZipUserFunctions;
FNVStart : PCharArray;
ZipOptions: TZPOpt;
PRootDir: PChar;
begin
Result:=false;
try
PRootDir:=StrAlloc(Length(RootDir)+1);
try
StrPCopy(PRootDir,RootDir);
ZipOptions:=ZpGetOptions;
ZipOptions.fJunkDir:=JunkDir;
ZipOptions.szRootDir:=PRootDir; //'C:\Zumpa\www\';
ZpSetOptions(ZipOptions);
{ precaution }
if Trim(ZipName) = '' then Exit;
if FileList.Count <= 0 then Exit;
{ initialize the dll with Proc functions }
ZipSetProcInitFunctions(ZUF);
{ number of files to zip }
ZipRec.argc := FileList.Count;
{ name of zip file - allocate room for null terminated string }
GetMem(ZipRec.lpszZipFN, Length(ZipName) + 1 );
ZipRec.lpszZipFN := StrPCopy( ZipRec.lpszZipFN, ZipName);
try
{ dynamic array allocation }
GetMem(ZipRec.FNV, ZipRec.argc * SizeOf(PChar));
FNVStart := ZipRec.FNV;
try
{ copy the file names from FileList to ZipRec.FNV dynamic array }
for i := 0 to ZipRec.argc - 1 do
begin
GetMem(ZipRec.FNV^[i], Length(FileList[i]) + 1 );
StrPCopy(ZipRec.FNV^[i], FileList[i]);
end;
try
{ send the data to the dll }
Result:=(ZpArchive(ZipRec)=0);
finally
{ release the memory for the file list }
ZipRec.FNV := FNVStart;
for i := (ZipRec.argc - 1) downto 0 do
FreeMem(ZipRec.FNV^[i], Length(FileList[i]) + 1 );
end;
finally
{ release the memory for the ZipRec.FNV dynamic array }
ZipRec.FNV := FNVStart;
FreeMem(ZipRec.FNV, ZipRec.argc * SizeOf(PChar));
end;
finally
{ release the memory for the FileName }
FreeMem(ZipRec.lpszZipFN, Length(ZipName) + 1 );
end;
finally
StrDispose(PRootDir);
end;
except
end;
end;
function ZipFile(ZipName, FileName : string; JunkDir: boolean; RootDir:
String): boolean;
var
FileList: TStrings;
begin
FileList:=TStringList.Create;
try
FileList.Add(FileName);
Result:=ZipFiles(ZipName,FileList,JunkDir,RootDir);
finally
FileList.Free;
end;
end;
function UnZipProcPrnt(Buffer: PChar; Size: ULONG): integer; stdcall;
begin
Result:=Size;
end;
function UnZipProcPassword(P: PChar; N: Integer; M, Name: PChar): integer;
stdcall;
begin
Result:=1;
end;
function UnZipProcService(CurFile: PChar; Size: ULONG): integer; stdcall;
begin
Result:=0;
end;
function UnZipProcReplace(FileName: PChar): integer; stdcall;
begin
Result:=1;
end;
procedure UnZipProcSound; stdcall;
begin
end;
procedure UnZipProcMessage(UnCompSize: ULONG; CompSize: ULONG; Factor: UINT;
Month: UINT; Day: UINT; Year: UINT; Hour: UINT; Minute: UINT; C: Char;
FileName: PChar; MethBuf: PChar; CRC: ULONG; Crypt: Char); stdcall;
begin
end;
procedure UnZipSetProcInitFunctions(var Z:TUserFunctions);
begin
with Z do
begin
@Print := @UnZipProcPrnt;
@Sound := @UnZipProcSound;
@Replace := @UnZipProcReplace;
@Password := @UnZipProcPassword;
@SendApplicationMessage := @UnZipProcMessage;
@ServCallBk := @UnZipProcService;
end;
end;
function UnZipFiles(FileName,Dir: String): boolean;
var
UF: TUserFunctions;
UnZipOptions: TDCL;
PDir: PChar;
PFileName: PChar;
begin
Result:=false;
try
PDir:=StrAlloc(Length(Dir)+1);
PFileName:=StrAlloc(Length(FileName)+1);
try
StrPCopy(PDir,Dir);
StrPCopy(PFileName,FileName);
{ set user functions }
UnZipSetProcInitFunctions(UF);
{ set unzip operation options }
FillChar(UnZipOptions,SizeOf(UnZipOptions),#0);
UnZipOptions.nDFlag:=1;
UnZipOptions.nOFlag:=1;
UnZipOptions.lpszExtractDir:=PDir;
UnZipOptions.lpszZipFN:=PFileName;
{ unzip }
Wiz_SingleEntryUnzip(0,nil,0,nil,UnZipOptions,UF);
Result:=true;
finally
StrDispose(PDir);
StrDispose(PFileName);
end;
except
end;
end;
end.
Odpovedá: likeapear
23. 9. 2002 14:07
> Zkus napsat cely postup (vcetne deklarace) , asi tam mas chybu.
> Pavel
posilam cely unit, snad to admin prezije...
D_Zip32 a D_UnZip32 jsou orig. unity s rozhranim k dll. problem nastava ve
funkci ZipFiles...
unit D_Web_Procs;
interface
uses
Windows, SysUtils, Classes, D_Zip32, D_UnZip32;
function ZipFiles(ZipName : string; FileList: TStrings; JunkDir: boolean;
RootDir: String): boolean;
function ZipFile(ZipName, FileName : string; JunkDir: boolean; RootDir:
String): boolean;
function UnZipFiles(FileName,Dir: String): boolean;
implementation
function ZipProcPrint(Buffer: PChar; Size: ULONG): integer; stdcall;
begin
Result:=Size;
end;
function ZipProcPassword(P: PChar; N: Integer; M, Name: PChar): integer;
stdcall;
begin
Result:=1;
end;
function ZipProcComment(Buffer: PChar): PChar; stdcall;
begin
Result:=Buffer;
end;
function ZipProcService(Buffer: PChar; Size: ULONG): integer; stdcall;
begin
Result:=0;
end;
procedure ZipSetProcInitFunctions(var Z:TZipUserFunctions);
begin
with Z do
begin
@Print := @ZipProcPrint;
@Comment := @ZipProcComment;
@Password := @ZipProcPassword;
@Service := @ZipProcService;
end;
ZpInit(Z);
end;
function ZipFiles(ZipName : string; FileList: TStrings; JunkDir: boolean;
RootDir: String): boolean;
var
i : integer;
ZipRec : TZCL;
ZUF : TZipUserFunctions;
FNVStart : PCharArray;
ZipOptions: TZPOpt;
PRootDir: PChar;
begin
Result:=false;
try
PRootDir:=StrAlloc(Length(RootDir)+1);
try
StrPCopy(PRootDir,RootDir);
ZipOptions:=ZpGetOptions;
ZipOptions.fJunkDir:=JunkDir;
ZipOptions.szRootDir:=PRootDir; //'C:\Zumpa\www\';
ZpSetOptions(ZipOptions);
{ precaution }
if Trim(ZipName) = '' then Exit;
if FileList.Count <= 0 then Exit;
{ initialize the dll with Proc functions }
ZipSetProcInitFunctions(ZUF);
{ number of files to zip }
ZipRec.argc := FileList.Count;
{ name of zip file - allocate room for null terminated string }
GetMem(ZipRec.lpszZipFN, Length(ZipName) + 1 );
ZipRec.lpszZipFN := StrPCopy( ZipRec.lpszZipFN, ZipName);
try
{ dynamic array allocation }
GetMem(ZipRec.FNV, ZipRec.argc * SizeOf(PChar));
FNVStart := ZipRec.FNV;
try
{ copy the file names from FileList to ZipRec.FNV dynamic array }
for i := 0 to ZipRec.argc - 1 do
begin
GetMem(ZipRec.FNV^[i], Length(FileList[i]) + 1 );
StrPCopy(ZipRec.FNV^[i], FileList[i]);
end;
try
{ send the data to the dll }
Result:=(ZpArchive(ZipRec)=0);
finally
{ release the memory for the file list }
ZipRec.FNV := FNVStart;
for i := (ZipRec.argc - 1) downto 0 do
FreeMem(ZipRec.FNV^[i], Length(FileList[i]) + 1 );
end;
finally
{ release the memory for the ZipRec.FNV dynamic array }
ZipRec.FNV := FNVStart;
FreeMem(ZipRec.FNV, ZipRec.argc * SizeOf(PChar));
end;
finally
{ release the memory for the FileName }
FreeMem(ZipRec.lpszZipFN, Length(ZipName) + 1 );
end;
finally
StrDispose(PRootDir);
end;
except
end;
end;
function ZipFile(ZipName, FileName : string; JunkDir: boolean; RootDir:
String): boolean;
var
FileList: TStrings;
begin
FileList:=TStringList.Create;
try
FileList.Add(FileName);
Result:=ZipFiles(ZipName,FileList,JunkDir,RootDir);
finally
FileList.Free;
end;
end;
function UnZipProcPrnt(Buffer: PChar; Size: ULONG): integer; stdcall;
begin
Result:=Size;
end;
function UnZipProcPassword(P: PChar; N: Integer; M, Name: PChar): integer;
stdcall;
begin
Result:=1;
end;
function UnZipProcService(CurFile: PChar; Size: ULONG): integer; stdcall;
begin
Result:=0;
end;
function UnZipProcReplace(FileName: PChar): integer; stdcall;
begin
Result:=1;
end;
procedure UnZipProcSound; stdcall;
begin
end;
procedure UnZipProcMessage(UnCompSize: ULONG; CompSize: ULONG; Factor: UINT;
Month: UINT; Day: UINT; Year: UINT; Hour: UINT; Minute: UINT; C: Char;
FileName: PChar; MethBuf: PChar; CRC: ULONG; Crypt: Char); stdcall;
begin
end;
procedure UnZipSetProcInitFunctions(var Z:TUserFunctions);
begin
with Z do
begin
@Print := @UnZipProcPrnt;
@Sound := @UnZipProcSound;
@Replace := @UnZipProcReplace;
@Password := @UnZipProcPassword;
@SendApplicationMessage := @UnZipProcMessage;
@ServCallBk := @UnZipProcService;
end;
end;
function UnZipFiles(FileName,Dir: String): boolean;
var
UF: TUserFunctions;
UnZipOptions: TDCL;
PDir: PChar;
PFileName: PChar;
begin
Result:=false;
try
PDir:=StrAlloc(Length(Dir)+1);
PFileName:=StrAlloc(Length(FileName)+1);
try
StrPCopy(PDir,Dir);
StrPCopy(PFileName,FileName);
{ set user functions }
UnZipSetProcInitFunctions(UF);
{ set unzip operation options }
FillChar(UnZipOptions,SizeOf(UnZipOptions),#0);
UnZipOptions.nDFlag:=1;
UnZipOptions.nOFlag:=1;
UnZipOptions.lpszExtractDir:=PDir;
UnZipOptions.lpszZipFN:=PFileName;
{ unzip }
Wiz_SingleEntryUnzip(0,nil,0,nil,UnZipOptions,UF);
Result:=true;
finally
StrDispose(PDir);
StrDispose(PFileName);
end;
except
end;
end;
end.
Odpovedá: Pavel Gazda
23. 9. 2002 13:24
>
> ZipOptions.szRootDir:=PRootDir; //'C:\Zumpa\www\';
> { name of zip file - allocate room for null terminated string }
> GetMem(ZipRec.lpszZipFN, Length(ZipName) + 1 );
> ZipRec.lpszZipFN := StrPCopy( ZipRec.lpszZipFN, ZipName);
> finally
> { release the memory for the FileName }
> FreeMem(ZipRec.lpszZipFN, Length(ZipName) + 1 );
> end;
>
Ahoj,
pro szRootDir pouzij stejny postup jako pro lpszZipFN.
Pavel
Odpovedá: likeapear
23. 9. 2002 14:18
> pro szRootDir pouzij stejny postup jako pro lpszZipFN.
>
> Pavel
dekuji za zajem, ale bohuzel to nepomohlo...debugger ukazuje vse jak ma byt,
ale proste se to chovat tak, jakoby szRootDir vubec nebyl nastaven. co mi
vrta hlavou nejvic je to, ze pokud to nastavim natvrdo, tak to funguje.
nevim jeslti to nemuze souviset s tim, ze pouzivame borlndmm.dll nebo nakym
nastavenim prekladace...
likeapear
Odpovedá: Pavel Gazda
23. 9. 2002 16:00
> vrta hlavou nejvic je to, ze pokud to nastavim natvrdo, tak to funguje.
to me prave vedlo k tomu, ze tam mas chybu
> nevim jeslti to nemuze souviset s tim, ze pouzivame borlndmm.dll nebo
nakym
zkousel si precist (programove) co jsi skutecne nastavil ?
Jinak ti neporadim, jen jsem poprve zareagoval, protoze sam mam nekdy
problemy s michanim String x PChar a myslel jsem, ze je chyba tam.
Pavel